const Router = require("@koa/router");
const router = new Router({ prefix: "/address" });
const { auth } = require("../middleware/authMiddleware");
const { validator } = require("../middleware/addrMiddleware");
const {
  create,
  findAll,
  update,
  remove,
  setDefault,
} = require("../controller/addrController");
// 1. 添加地址
router.post(
  "/",
  auth,
  validator({
    consignee: "string",
    phone: { type: "string", format: /^1\d{10}/ },
    address: "string",
  }),
  create
);
// 2. 获取地址列表
router.get("/", auth, findAll);
// 3. 修改地址
router.put(
  "/:id",
  auth,
  validator({
    consignee: "string",
    phone: { type: "string", format: /^1\d{10}/ },
    address: "string",
  }),
  update
);

// 4. 删除地址
router.delete("/:id", auth, remove);

// 5. 设置默认地址
router.patch("/:id", auth, setDefault);
module.exports = router;
